package distributedRE.model;

import java.util.ArrayList;
import java.util.Hashtable;

public class Document {

	private long id;
	private String url;
	private long db_id;
	private Hashtable<String, Hashtable<Long, ArrayList<Tuple>>> tuples;
	

	public Document(long id, String url, long db_id){
		
		this.id = id;
		this.url = url;
		this.db_id = db_id;
		tuples = new Hashtable<String, Hashtable<Long,ArrayList<Tuple>>>();
	}
	
	public long getId() {
		
		return id;
		
	}

	public long getDbId(){
		return db_id;
	}
	
	public String getPath() {
		
		return url;
		
	}

	public boolean equals(Object o){
		return (id == ((Document)o).id);
	}

	public void addExtractedTuple(String InformationExtractionId, long relationId, Tuple tuple) {
		
		Hashtable<Long,ArrayList<Tuple>> relationTuples = tuples.get(InformationExtractionId);
		
		if (relationTuples == null){
			
			relationTuples = new Hashtable<Long, ArrayList<Tuple>>();
			
		}
		
		ArrayList<Tuple> tuplesFor = relationTuples.get(new Long(relationId));
		
		if (tuplesFor == null){
			
			tuplesFor = new ArrayList<Tuple>();
			
		}
		
		if (!tuplesFor.contains(tuple)){
			tuplesFor.add(tuple);
		}
		relationTuples.put(new Long(relationId), tuplesFor);
		
		tuples.put(InformationExtractionId, relationTuples);
		
	}

	public ArrayList<Tuple> getTuples(String informationExtractionId, long relationId){
		ArrayList<Tuple> ret = new ArrayList<Tuple>();
		
		if (tuples.containsKey(informationExtractionId)){
			Hashtable<Long, ArrayList<Tuple>> relationTuple = tuples.get(informationExtractionId);
			if (relationTuple.containsKey(new Long(relationId))){
				return relationTuple.get(new Long(relationId));
			}
		}
				
		return ret;
	}
	
}
